<?php

function register_my_menus()
{
    register_nav_menus(
        array(
            'header-menu' => __('Header Menu'),
            'top-menu' => __('Top Menu'),
            'footer-menu' => __('Footer Menu'),
        )
    );
}

add_action('init', 'register_my_menus');


//include 'menu/OptionPlugins.php';
// Thêm ảnh Thumbnail để hiển thị sản phẩm
add_theme_support('post-thumbnails');

function get_strcontent($IP_content, $IP_limit)
{

//if length of $IPcontent is shorter $IP_limit
    if (strlen($IP_content) <= $IP_limit)
    {
        return $IP_content;
    }
    else
    {
        if (strpos($IP_content, " ", $IP_limit) >= $IP_limit)
        {
            $new_limit = strpos($IP_content, " ", $IP_limit);

            $new_content = substr($IP_content, 0, $new_limit) . "...";
            return $new_content;
        }

        $new_content = substr($IP_content, 0, $IP_limit) . "...";
        return $new_content;
    }
}

//add_action('init', 'get_strcontent');
// Đăng ký 1 sidebar
$left_args = array(
    'name' => sprintf(__('Cột trái'), $i),
    'id' => "sidebar-left",
    'description' => '',
    'class' => '',
    'before_widget' => '<div class="bar_left">',
    'after_widget' => "</div>",
    'before_title' => '<div class="heder_bar">',
    'after_title' => "</div>",
);
register_sidebar($left_args);

/**
 * Widget Hỗ trợ qua Yahoo
 */
class Yahoo_support_Widget extends WP_Widget
{

    public function __construct()
    {
        parent::__construct(
            'yahoo_widget', // Base ID
            'Yahoo hỗ trợ', // Name
            array('description' => __('Yahoo hỗ trợ', 'text_domain'),) // Args
        );
    }

    /**
     * Front-end display of widget.
     *
     * @see WP_Widget::widget()
     *
     * @param array $args     Widget arguments.
     * @param array $instance Saved values from database.
     */
    public function widget($args, $instance)
    {
        extract($args);
        $name1 = apply_filters('widget_title', $instance['name1']);
        $phone1 = apply_filters('widget_title', $instance['phone1']);
        $ym1 = apply_filters('widget_title', $instance['ym1']);

        $name2 = apply_filters('widget_title', $instance['name2']);
        $phone2 = apply_filters('widget_title', $instance['phone2']);
        $ym2 = apply_filters('widget_title', $instance['ym2']);

        echo $before_widget;
        if (!empty($title)) echo $before_title . $title . $after_title;
        ?>
        <!-- Support online-->
        <div class="heder_bar" id="support" >
            Hỗ trợ
        </div>
        <div class="bar_bg " id="support_content">
            <p><?php echo $name1 ?> - <?php echo $phone1 ?></p>
            <br/>
            <a href="ymsgr:sendim?<?php echo $ym1 ?>">
                <img src='http://opi.yahoo.com/online?u=<?php echo $ym1 ?>&m=g&t=2'/>
            </a>         
            <br/>
            <br/>
            <p><?php echo $name2 ?> - <?php echo $phone2 ?></p>
            <br/>
            <a href="ymsgr:sendim?<?php echo $ym1 ?>">
                <img src='http://opi.yahoo.com/online?u=<?php echo $ym2 ?>&m=g&t=2'/>
            </a>            
        </div>
        <!-- end support online-->

        <?php
        echo $after_widget;
    }

    /**
     * Sanitize widget form values as they are saved.
     *
     * @see WP_Widget::update()
     *
     * @param array $new_instance Values just sent to be saved.
     * @param array $old_instance Previously saved values from database.
     *
     * @return array Updated safe values to be saved.
     */
    public function update($new_instance, $old_instance)
    {
        $instance = array();
        $instance['name1'] = strip_tags($new_instance['name1']);
        $instance['name2'] = strip_tags($new_instance['name2']);
        $instance['ym1'] = strip_tags($new_instance['ym1']);
        $instance['ym2'] = strip_tags($new_instance['ym2']);
        $instance['phone1'] = strip_tags($new_instance['phone1']);
        $instance['phone2'] = strip_tags($new_instance['phone2']);

        return $instance;
    }

    /**
     * Back-end widget form.
     *
     * @see WP_Widget::form()
     *
     * @param array $instance Previously saved values from database.
     */
    public function form($instance)
    {
        $name1 = isset($instance['name1']) ? $instance['name1'] : '';
        $name2 = isset($instance['name2']) ? $instance['name2'] : '';
        $phone1 = isset($instance['phone1']) ? $instance['phone1'] : '';
        $phone2 = isset($instance['phone2']) ? $instance['phone2'] : '';
        $ym1 = isset($instance['ym1']) ? $instance['ym1'] : '';
        $ym2 = isset($instance['ym2']) ? $instance['ym2'] : '';
        ?>
        <p>
            <b>Hỗ trợ 1</b>
            <br/>
            <label><?php _e('Tên hiển thị:'); ?></label>
            <input class="widefat"
                   id="<?php echo $this->get_field_id('name1'); ?>"
                   name="<?php echo $this->get_field_name('name1'); ?>"
                   type="text" value="<?php echo esc_attr($name1); ?>" />
            <label><?php _e('Số điện thoại:'); ?></label>
            <input class="widefat"
                   id="<?php echo $this->get_field_id('phone1'); ?>"
                   name="<?php echo $this->get_field_name('phone1'); ?>"
                   type="text" value="<?php echo esc_attr($phone1); ?>" />
            <label><?php _e('Tài khoản yahoo:'); ?></label>
            <input class="widefat"
                   id="<?php echo $this->get_field_id('ym1'); ?>"
                   name="<?php echo $this->get_field_name('ym1'); ?>"
                   type="text" value="<?php echo esc_attr($ym1); ?>" />

        <hr/>
        <b>Hỗ trợ 2</b>
        <br/>
        <label><?php _e('Tên hiển thị:'); ?></label>
        <input class="widefat"
               id="<?php echo $this->get_field_id('name2'); ?>"
               name="<?php echo $this->get_field_name('name2'); ?>"
               type="text" value="<?php echo esc_attr($name2); ?>" />
        <label><?php _e('Số điện thoại:'); ?></label>
        <input class="widefat"
               id="<?php echo $this->get_field_id('phone2'); ?>"
               name="<?php echo $this->get_field_name('phone2'); ?>"
               type="text" value="<?php echo esc_attr($phone2); ?>" />
        <label><?php _e('Tài khoản yahoo:'); ?></label>
        <input class="widefat"
               id="<?php echo $this->get_field_id('ym2'); ?>"
               name="<?php echo $this->get_field_name('ym2'); ?>"
               type="text" value="<?php echo esc_attr($ym2); ?>" />            
        </p>
        <?php
    }

}

// class Foo_Widget
// register Foo_Widget widget
add_action('widgets_init', create_function('', 'register_widget( "yahoo_support_widget" );'));

/**
 * Categories widget class
 *
 * @since 2.8.0
 */
class Megalab_Sanpham extends WP_Widget
{

    function __construct()
    {
        parent::__construct(
            'megalab_sanpham', // Base ID
            'Megalab Sản phẩm', // Name
            array('description' => __('Danh sách sản phẩm', 'text_domain'),) // Args
        );
    }

    function widget($args, $instance)
    {
        extract($args);

        $title = apply_filters('widget_title', empty($instance['title']) ? __('Sản phẩm') : $instance['title'], $instance, $this->id_base);

        echo $before_widget;
        if ($title) echo $before_title . $title . $after_title;

        $cat_args = array(
            'show_option_all' => '',
            'orderby' => 'id',
            'order' => 'ASC',
            'style' => 'list',
            'show_count' => 0,
            'hide_empty' => 0,
            'use_desc_for_title' => 1,
            'child_of' => 1,
            'feed' => '',
            'feed_type' => '',
            'feed_image' => '',
            'exclude' => '',
            'exclude_tree' => '',
            'include' => '',
            'hierarchical' => true,
            'title_li' => '',
            'show_option_none' => __('No categories'),
            'number' => null,
            'echo' => 1,
            'depth' => 0,
            'current_category' => 0,
            'pad_counts' => 0,
            'taxonomy' => 'category',
            'walker' => 'Walker_Category'
        );
        ?>
        <div class="tile_separated"></div>
        <div class="list_category_wrap">
            <ul class="list_category">
        <?php
        wp_list_categories($cat_args);
        ?>
            </ul>
            <div class="clear"></div>
        </div>
        <?php
        echo $after_widget;
    }

    function update($new_instance, $old_instance)
    {
        $instance = $old_instance;
        $instance['title'] = strip_tags($new_instance['title']);
        return $instance;
    }

    function form($instance)
    {
        //Defaults
        $instance = wp_parse_args((array) $instance, array('title' => ''));
        $title = esc_attr($instance['title']);
        ?>
        <p>
            <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
            <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
                   name="<?php echo $this->get_field_name('title'); ?>"
                   type="text" value="<?php echo $title; ?>" />
        </p>
        <?php
    }

}

// register Foo_Widget widget
add_action('widgets_init', create_function('', 'register_widget( "megalab_sanpham" );'));

/**
 * Hãng sản xuất widget class
 *
 * @since 2.8.0
 */
class Megalab_Hangsx extends WP_Widget
{

    function __construct()
    {
        parent::__construct(
            'megalab_hangsx', // Base ID
            'Megalab Hãng sản xuất', // Name
            array('description' => __('Danh sách hãng sản xuất', 'text_domain'),) // Args
        );
    }

    function widget($args, $instance)
    {
        extract($args);

        $title = apply_filters('widget_title', empty($instance['title']) ? __('Sản phẩm') : $instance['title'], $instance, $this->id_base);

        echo $before_widget;
        if ($title) echo $before_title . $title . $after_title;

        $cat_args = array(
            'show_option_all' => '',
            'show_option_none' => 'Chọn Hãng sản xuất',
            'orderby' => 'ID',
            'order' => 'ASC',
            'show_count' => 0,
            'hide_empty' => 0,
            'child_of' => 17,
            'exclude' => '',
            'echo' => 1,
            'selected' => 0,
            'hierarchical' => 0,
            'name' => 'cat',
            'id' => '',
            'class' => 'postform',
            'depth' => 0,
            'tab_index' => 0,
            'taxonomy' => 'category',
            'hide_if_empty' => false
        );
        ?>
        <div class="tile_separated"></div>
        <div class="list_category_wrap">
            <div class="bar_bg">
        <?php
        wp_dropdown_categories($cat_args);
        ?>
            </div>
            <script type="text/javascript">
                /* <![CDATA[ */
                var dropdown = document.getElementById("cat");
                function onCatChange() {
                    if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
                        location.href = "<?php bloginfo('url'); ?>?cat="+dropdown.options[dropdown.selectedIndex].value;
                    }
                }
                dropdown.onchange = onCatChange;
                /* ]]> */
            </script>
        </div>
        <?php
        echo $after_widget;
    }

    function update($new_instance, $old_instance)
    {
        $instance = $old_instance;
        $instance['title'] = strip_tags($new_instance['title']);
        return $instance;
    }

    function form($instance)
    {
        //Defaults
        $instance = wp_parse_args((array) $instance, array('title' => ''));
        $title = esc_attr($instance['title']);
        ?>
        <p>
            <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
            <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
                   name="<?php echo $this->get_field_name('title'); ?>"
                   type="text" value="<?php echo $title; ?>" />
        </p>
        <?php
    }

}

// register Foo_Widget widget
add_action('widgets_init', create_function('', 'register_widget( "megalab_hangsx" );'));

class Megalab_BanDo extends WP_Widget
{

    function __construct()
    {
        parent::__construct(
            "megalab_bando", "Bản đồ đến công ty", array('Description' => __('Bản đồ đến công ty', 'text_domain'),));
    }

    //output the  options to be saved
    public function update($new_instance, $old_instance)
    {
        
    }

    //output the content of the widget
    public function widget($arg, $instance)
    {

        echo "<div class='bar_left'><div class='heder_bar'>Bản đồ</div>";
        echo "<div class='tile_separated'></div>";
        echo '<iframe width="220" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=vi&amp;geocode=&amp;q=Ho%C3%A0ng+C%E1%BA%A7u,+%C4%90%E1%BB%91ng+%C4%90a,+H%C3%A0+N%E1%BB%99i,+Vi%E1%BB%87t+Nam&amp;aq=1&amp;oq=Ho%C3%A0ng+c%E1%BA%A7u&amp;sll=21.016212,105.824668&amp;sspn=0.011077,0.019741&amp;ie=UTF8&amp;hq=&amp;hnear=Ho%C3%A0ng+C%E1%BA%A7u,+%C4%90%E1%BB%91ng+%C4%90a,+H%C3%A0+N%E1%BB%99i,+Vi%E1%BB%87t+Nam&amp;t=m&amp;ll=21.016172,105.82469&amp;spn=0.028042,0.018883&amp;z=14&amp;iwloc=A&amp;output=embed"></iframe><br /><small><a href="https://maps.google.com/maps?f=q&amp;source=embed&amp;hl=vi&amp;geocode=&amp;q=Ho%C3%A0ng+C%E1%BA%A7u,+%C4%90%E1%BB%91ng+%C4%90a,+H%C3%A0+N%E1%BB%99i,+Vi%E1%BB%87t+Nam&amp;aq=1&amp;oq=Ho%C3%A0ng+c%E1%BA%A7u&amp;sll=21.016212,105.824668&amp;sspn=0.011077,0.019741&amp;ie=UTF8&amp;hq=&amp;hnear=Ho%C3%A0ng+C%E1%BA%A7u,+%C4%90%E1%BB%91ng+%C4%90a,+H%C3%A0+N%E1%BB%99i,+Vi%E1%BB%87t+Nam&amp;t=m&amp;ll=21.016172,105.82469&amp;spn=0.028042,0.018883&amp;z=14&amp;iwloc=A" style="color:#0000FF;text-align:left">Xem Bản đồ cỡ lớn hơn</a></small>';
        echo '</div>';
    }

}

add_action('widgets_init', create_function('', 'register_widget( "Megalab_BanDo" );'));

class Megalab_Pageview extends WP_Widget
{

    function __construct()
    {
        parent::__construct(
            "megalab_pageview", "Lượt truy cập", array('Description' => __('Lượt truy cập', 'text_domain'),));
    }

    //output the  options to be saved
    public function update($new_instance, $old_instance)
    {
        
    }

    //output the content of the widget
    public function widget($arg, $instance)
    {
        echo "<div class='bar_left'><div class='heder_bar'>Lượt truy cập</div>
              <div class='bar_bg'>";
        echo '<!-- Histats.com  START  (standard)-->
<script type="text/javascript">document.write(unescape("%3Cscript src=%27http://s10.histats.com/js15.js%27 type=%27text/javascript%27%3E%3C/script%3E"));</script>
<a href="http://www.histats.com" target="_blank" title="hit tracker" ><script  type="text/javascript" >
try {Histats.start(1,2035044,4,1044,200,30,"00010000");
Histats.track_hits();} catch(err){};
</script></a>
<noscript><a href="http://www.histats.com" target="_blank"><img  src="http://sstatic1.histats.com/0.gif?2035044&101" alt="hit tracker" border="0"></a></noscript>
<!-- Histats.com  END  -->
            ';
        echo "</div></div>";
    }

}

add_action('widgets_init', create_function('', 'register_widget( "Megalab_Pageview" );'));
?>